package com.metaboot.demo.service.impl;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.metaboot.common.utils.StringUtils;
import com.metaboot.demo.domain.DemoTree;
import com.metaboot.demo.mapper.DemoTreeMapper;
import com.metaboot.demo.service.IDemoTreeService;

/**
 * 树表演示Service业务层处理
 * 
 * @author theodo
 * @date 2021-12-01
 */
@Service
public class DemoTreeServiceImpl extends ServiceImpl<DemoTreeMapper, DemoTree> implements IDemoTreeService {
    @Autowired
    private DemoTreeMapper demoTreeMapper;

    /**
     * 查询树表演示
     * 
     * @param id 树表演示主键
     * @return 树表演示
     */
    @Override
    public DemoTree selectDemoTreeById(Long id) {
        return demoTreeMapper.selectById(id);
    }
    
    /**
	 * 获取查询条件
	 * 
	 * @param demoTree 树表演示
	 * @return 树表演示
	 */
	@SuppressWarnings("unused")
	private LambdaQueryWrapper<DemoTree> buildQueryWrapper(DemoTree demoTree) {
        Map<String, Object> params = demoTree.getParams();
        LambdaQueryWrapper<DemoTree> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(demoTree.getName()), DemoTree::getName, demoTree.getName());
        lqw.eq(StringUtils.isNotBlank(demoTree.getStatus()), DemoTree::getStatus, demoTree.getStatus());
        return lqw;
    }

    /**
     * 查询树表演示列表
     * 
     * @param demoTree 树表演示
     * @return 树表演示
     */
    @Override
    public List<DemoTree> selectDemoTreeList(DemoTree demoTree) {
        return demoTreeMapper.selectList(buildQueryWrapper(demoTree));
    }

    /**
     * 新增树表演示
     * 
     * @param demoTree 树表演示
     * @return 结果
     */
    @Override
    public int insertDemoTree(DemoTree demoTree) {
        return demoTreeMapper.insert(demoTree);
    }

    /**
     * 修改树表演示
     * 
     * @param demoTree 树表演示
     * @return 结果
     */
    @Override
    public int updateDemoTree(DemoTree demoTree) {
        return demoTreeMapper.updateById(demoTree);
    }

    /**
     * 批量删除树表演示
     * 
     * @param ids 需要删除的树表演示主键
     * @return 结果
     */
    @Override
    public int deleteDemoTreeByIds(Collection<Long> ids) {
        return demoTreeMapper.deleteBatchIds(ids);
    }

    /**
     * 删除树表演示信息
     * 
     * @param id 树表演示主键
     * @return 结果
     */
    @Override
    public int deleteDemoTreeById(Long id) {
        return demoTreeMapper.deleteById(id);
    }
}
